package com.google.coffeeshop.gui.desktop.orderpayment;

import java.awt.CardLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import vn.bang.utility.StringUtil;

import com.google.coffeeshop.GeneralConstants;
import com.google.coffeeshop.entity.SeatDTO;

public class SeatButton extends JButton {
	private static final long serialVersionUID = 1L;

	private SeatDTO seat;
	
	public SeatButton(SeatDTO seat) {
		this.seat = seat;
		setText(seat.getSeatName());
		setIcon(this, seat.getStatus());
		setSize(100, 100);
		setLayout(new CardLayout(0, 0));
		setVerticalTextPosition(SwingConstants.BOTTOM);
	    setHorizontalTextPosition(SwingConstants.CENTER);
	}
	
	public SeatDTO getSeat() {
		return seat;
	}

	private void setIcon(JButton button, Integer statusId) {
		String icon48Package = "/com/google/coffeeshop/gui/desktop/icon/size48/";
		String iconName = "";
		if (GeneralConstants.SEAT_USABLE_STATUS.equals(statusId)) {
			iconName = "seat-green-48.png";
		} else if (GeneralConstants.SEAT_BUSY_STATUS.equals(statusId)) {
			iconName = "seat-red-48.png";
		} else if (GeneralConstants.SEAT_STOP_STATUS.equals(statusId)) {
			iconName = "seat-yellow-48.png";
		}
		if (StringUtil.isNullOrEmpty(iconName)) {
			return;
		}
		button.setIcon(new ImageIcon(SeatButton.class.getResource(icon48Package + iconName)));
	}
	
}
